if (SERVER) then
	AddCSLuaFile("shared.lua")
	SWEP.Weight		= 5
	SWEP.AutoSwitchTo	= false
	SWEP.AutoSwitchFrom	= false
	SWEP.HoldType		= "Pistol"
end

if (CLIENT) then
	SWEP.DrawAmmo			= false
	SWEP.Instructions		= "Binoculars: Hold left to zoom in and right click to zoom out."
	SWEP.Author				= ""
	SWEP.DrawCrosshair		= false
	SWEP.Slot				= 5
end

SWEP.PrintName			= "Binoculars"
SWEP.Spawnable     			= true
SWEP.AdminSpawnable  		= true
 
SWEP.ViewModel		= "models/weapons/v_binoculars.mdl"
SWEP.WorldModel		= "models/weapons/w_binoculars.mdl"

SWEP.Primary.ClipSize		= -1
SWEP.Primary.DefaultClip	= -1
SWEP.Primary.Ammo = "none"
SWEP.Primary.Automatic		= true

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Ammo = false
SWEP.Secondary.Automatic = true

SWEP.ZoomDistCurrent = 50
SWEP.DrawZoom = false

SWEP.Other = true

function SWEP:Initialize()
	self:SetWeaponHoldType("normal")
end 

function SWEP:Deploy()
	if (SERVER) then self.Owner:DrawWorldModel(false) end
end
 
function SWEP:PrimaryAttack(ply)
	if self.ZoomDistCurrent > 1 then
		self.ZoomDistCurrent = self.ZoomDistCurrent - 1
		self.Owner:SetFOV(self.ZoomDistCurrent, 0)
		if(SERVER) then self.Owner:DrawViewModel(false) end
		self.DrawZoom = true
	else
		self:SetNextPrimaryFire(CurTime() + 1)
	end
end

function SWEP:Holster()
	self.Owner:SetFOV(0, 0) 
	self.ZoomDistCurrent = 50
	return true
end

function SWEP:SecondaryAttack(ply)
	if self.ZoomDistCurrent <= 50 then
		self.ZoomDistCurrent = self.ZoomDistCurrent + 1
		self.Owner:SetFOV(self.ZoomDistCurrent, 0)
		self.DrawZoom = true
	else
		self.Owner:SetFOV(0, 0)
		if(SERVER) then self.Owner:DrawViewModel(true) end
		self.Weapon:SetNextSecondaryFire(CurTime() + 1)
		self.DrawZoom = false
	end
end

function SWEP:Reload()
	
end

function SWEP:DrawHUD()
			if(self.DrawZoom == true) then
			local x = ScrW()
			local y = ScrH()
			local w = x/2
			local h = y/2
			
			render.UpdateRefractTexture()
			if x > y*4/3 then
				local e2s = (x - (y*4/3))/2 --algebra to find the center of the screen and shit blah blah i dont wanna bore you (for widescreen monitors (e2s means edge to side of scope)			
				surface.SetTexture(surface.GetTextureID("gmod/scope"))  --regular sCOPE overlay
				surface.SetDrawColor(0, 0, 0, 255)
				surface.DrawTexturedRect(e2s, 0, x-(e2s*2), y)  --gets your screen resolution minus the extra edges
				
				surface.SetDrawColor(0, 0, 0, 255)
				surface.DrawRect(0, 0, e2s, y)
				
				surface.SetDrawColor(0, 0, 0, 255)
				surface.DrawRect(x-e2s, 0, e2s, y)
			else			
				surface.SetTexture(surface.GetTextureID("gmod/scope"))  --regular sCOPE overlay
				surface.SetDrawColor(0, 0, 0, 255)
				surface.DrawTexturedRect(0, 0, x, y) --gets your screen resolution
			end

			surface.SetDrawColor(0, 0, 0, 255) 
			surface.DrawLine(w - x, h, w, h)
			surface.DrawLine(w + x, h, w, h)
			surface.DrawLine(w, h - x, w, h)
			surface.DrawLine(w, h + x, w, h)
			
			if(LocalPlayer():GetEyeTraceNoCursor().Entity:IsPlayer() == true)then
			local str=Localize(LocalPlayer():GetEyeTraceNoCursor().Entity:GetClass(), LocalPlayer():GetEyeTraceNoCursor().Entity:GetClass())
					local scanner = LocalPlayer():GetNWBool("scannered")
					if (scanner == true) then
					DrawPlayerInfo(LocalPlayer():GetEyeTrace().Entity, scanner)
					end
			end

			end
end

function SWEP:DrawWeaponSelection(x, y, wide, tall, alpha)
	draw.SimpleText("H", "CSSelectIcons", x + wide/2, (y + tall*0.2)-10, Color(255, 210, 0, 255), TEXT_ALIGN_CENTER)
end